<?php
namespace app\admin\controller;

use app\common\model\UserWalletDynamicLog as UserWalletDynamicLogModel;

class UserDynamic extends ControllerBase {
	public function _initialize() {
		$this -> checkLogin();

		$this -> checkAuthorization();
	}

	public function check() {
		$this -> view -> assign('userWalletDynamicLogs', UserWalletDynamicLogModel::alias('u_w_d_l')
			-> join('league_user u', 'u_w_d_l.user_id = u.user_id')
			-> field(
				'u_w_d_l.user_wallet_dynamic_log_id, u_w_d_l.type, u_w_d_l.price, u_w_d_l.create_time, u_w_d_l.remark, u_w_d_l.is_state, ' .
				'u.username, u.realname, u.phone, u.bank_code'
			)
			->order('u_w_d_l.is_state ASC, u_w_d_l.user_wallet_dynamic_log_id DESC')
			-> paginate(10));

		return $this -> view -> fetch();
	}

	public function handleCheck() {
		$getUserWalletDynamicLog = UserWalletDynamicLogModel::get(['user_wallet_dynamic_log_id' => $this -> request -> get('user_wallet_dynamic_log_id', 0, 'int')]);

		$getUserWalletDynamicLog -> is_state = 1;
		if(!$getUserWalletDynamicLog -> save()) {
			echo '<meta charset="utf-8"><script>alert("审核失败");window.location.href="/shuashuale/user/dynamic/check";</script>';exit;
		}

		echo '<meta charset="utf-8"><script>alert("审核成功");window.location.href="/shuashuale/user/dynamic/check";</script>';exit;
	}
}